package com.example.demo.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.demo.mapper.MenuMapper;
import com.example.demo.pojo.Menu;
import com.example.demo.service.MenuService;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class MenuServiceImpl extends ServiceImpl<MenuMapper, Menu> implements MenuService {
    @Override
    public List<Menu> getMenuListByUserId(Integer userId) {
        //一级菜单
        List<Menu> menuListByUserId = this.baseMapper.getMenuListByUserId(userId, 0);
        for (Menu menu : menuListByUserId) {
            //二级菜单
            List<Menu> menuListByUserId1 = this.baseMapper.getMenuListByUserId(userId, menu.getMenuId());
            menu.setChildren(menuListByUserId1);
        }
        return menuListByUserId;
    }
}
